/**=========================================================
 * Controller: SystemCacheController
  =========================================================*/
App.controller('SystemCacheController', ['$scope', 'Utils', 'HttpUtils', 'SimpleUiGrid', 'SimpleSelect',
    function($scope, utils, httpUtils, simpleUiGridService, simpleSelectService) {
        //===========================commonQueryUrlGrid=================================            
        var typeSelect = simpleSelectService.init($scope,
            {
                optionModel: 'type',
                remote: false,
                datas: [
                    {
                        value: 'userRole',
                        name: '用户角色'
                    },
                    {
                        value: 'roleMenu',
                        name: '角色菜单'
                    },
                    {
                        value: 'menuRole',
                        name: '菜单角色'
                    },
                    {
                        value: 'urlMenu',
                        name: '链接菜单'
                    }
                ],
                initValue: 'userRole'
            }
        );
        
        $scope.searchCacheGrid = function() {
            var params = {};
            params.key = $scope.key;
            params.type = typeSelect.getSelected();
 
            httpUtils.get(cacheGrid.options.url,params,
                function (result) {
                    var columns = [];
                    var datas = [];
  
                    if (params.type == "roleMenu"){
                        columns = [
                            {
                                displayName: 'ID',
                                field: 'tid'
                            },
                            {
                                displayName: '菜单',
                                field: 'label'
                            },
                            {
                                displayName: '路由',
                                field: 'sref'
                            }
                        ];
                        if (!utils.isEmpty(result.datas)){
                            datas = result.datas;
                        }
                    } else {
                        columns = [
                            {
                                displayName: '键值',
                                field: 'value'
                            }
                        ];
                        if (!utils.isEmpty(result.datas)){
                            for (var i = 0; i < result.datas.length; i++){
                                datas.push({value: result.datas[i]});
                            }
                        }
                    }
                    
                    $scope['cacheGridOptions'].columnDefs = columns;
                    
                    $scope['cacheGridOptions'].data = datas;
                }
            )
        }; 

        var cacheGrid = simpleUiGridService.init($scope, 
            {
                optionModel: 'cacheGridOptions',
                pageOptionModel: 'cacheGridPageOptions',
                gridApi: 'cacheGridApi',
                url: '/cache/queryCache',
                needPage: false,
                needExport: false
            }
        );

    }
]);
